package com.ty.framework.config;

import com.ty.common.converter.StringToDateConverter;
import com.ty.framework.web.interceptor.JwtIntercpetor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/** @author 天宇宇宇宇宇 @Data 2020/12/16 10:21 */
@Configuration
public class WvcConfig implements WebMvcConfigurer {

  /** 添加自定义的Converter */
  @Override
  public void addFormatters(FormatterRegistry registry) {
    registry.addConverter(new StringToDateConverter());
  }

  @Bean
  public JwtIntercpetor jwtIntercpetor() {
    return new JwtIntercpetor();
  }
  /**
   * 添加拦截器
   *
   * @param registry 注册表
   */
  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    registry
        .addInterceptor(jwtIntercpetor())
        .addPathPatterns("/**")
        .excludePathPatterns("/admin/login", "/admin/captcha", "/admin/logout");
  }
}
